<!-- 用例产品、项目模块 -->
<template>
  <div class="div_box">
    <el-row :gutter="5">
      <el-col :span="5">
        <card-create :submit="createProduct" />
      </el-col>
      <el-col v-for="(product, index) in productList" :key="index" :span="5">
        <card :content="product" />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { searchAll, create, deleteP } from '@/api/auto/product.js'
import Card from '@/components/Card/product-card'
import CardCreate from '@/components/Card/product-create-card'
export default {
  name: 'AutoCaseProduct',
  components: { Card, CardCreate },
  data() {
    return {
      productList: []
    }
  },
  created() {
    this.getProductList()
  },
  methods: {
    getProductList() {
      searchAll(1, 99999).then(respnose => {
        if (respnose && respnose.code === 200) {
          const { data } = respnose
          this.productList = data.content
        } else {
          this.$message.error(respnose.message)
        }
      })
    },
    handleDeleteClick(id) {
      this.$confirm('此操作将永久删除该项目, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteP(id).then(respnose => {
          if (respnose && respnose.code === 200) {
            this.$message.success(respnose.message)
            this.getProductList()
          } else {
            this.$message.error(respnose.message)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    createProduct(productForm) {
      create(productForm).then(respnose => {
        if (respnose && respnose.code === 200) {
          this.$message.success(respnose.message)
          this.getProductList()
        } else {
          this.$message.error(respnose.message)
        }
      })
    }
  }
}
</script>

<style scoped="scoped">
.div_box {
  border: 1px solid #eee;
  padding-left: 15px;
  padding-right: 15px;
  padding-top: 15px;
  padding-bottom: 10px;
  margin-top: 10px;
  margin-bottom: 10px;
  width: 100%;
  min-height: 800px;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
}

.el-col {
  margin: 10px;
}
</style>
